COMP3141 Software System Design and Implementation

COMP3141: Software System Design and Implementation

Term 2, 2023

Quiz 1 (Week 1)

Hint: some of these questions can be a bit subtle, and will require you to think it through. Don't rush it, and don't try it without tool support. You should make full use of the GHCi Haskell interpreter, and Hoogle, as appropriate.

1 Circularity

1.1 Question 1

What is the answer to this question?

Hint: the answer to this question can be found on the Ed forums. If you're not on the forums already, you should be; it's the place for discussion and announcements. See instructions on the home page if you're having trouble accessing them.

  1. Catsmeat Potter-Pirbright
  2. Roderick Spode
  3. Gussie Fink-Nottle
  4. Madeline Bassett

2 Typing

In what follows, assume for the sake of simplicity that all numeric literals have type Int. Determine the type of the following Haskell expressions!

2.1 Question 2

"hello world"
  1. char*
  2. [Char]
  3. string
  4. [String]

2.2 Question 3

[('a',5,6),('b',7,8)]
  1. (Char, Int, Int)
  2. [(Char,Int,Int)]
  3. ([Char,Int,Int])
  4. ([Char],[Int],[Int])

2.3 Question 4

snd ("hello", ("world":[]))
  1. [[Char]]
  2. [[[Char]]]
  3. [Char]
  4. String

2.4 Question 5

map (\x -> x + 1)
  1. [a] -> [b]
  2. Int -> Int
  3. [Int] -> [Int]
  4. (Int -> Int) -> [Int] -> [Int]
  5. Invalid, as not enough arguments are given to map.

3 Parentheses

Choose all equivalent parenthesizations of the given expressions.

3.1 Question 6

reverse "hello" ++ "world"
  1. (reverse "hello") ++ "world"
  2. ((reverse "hello") ++ "world")
  3. reverse ("hello" ++ "world")
  4. reverse ("hello" ++) "world"

3.2 Question 7

constant3 :: a -> b -> c -> a
  1. constant3 :: a -> (b -> c -> a)
  2. constant3 :: (a -> b) -> (c -> a)
  3. constant3 :: a -> (b -> (c -> a))
  4. constant3 :: a -> [b -> c -> a]

4 Evaluation

Choose all expressions that are equivalent to the given expressions. By "equivalent", we mean that the expressions evaluate to equal results. We consider two functions equal if, for any input, they produce equal outputs (functional extensionality).

4.1 Question 8

Note: The functions ord and chr are from Data.Char. They convert Char values to/from their ASCII (or unicode) numbers, respectively. For these questions, the answers may have a more general type than the original expression. So long as a given answer has equivalent behaviour for the type of the original expression, we consider the answer to be equivalent.

let increment x = 1 + x
in \xs -> map chr (map increment (map ord xs))
  1. map chr . map (1+) . map ord
  2. map (chr . (1+) . ord)
  3. map succ
  4. map chr $ map (1+) $ map ord
  5. \xs -> map chr . map (1+) $ map ord xs

2023-08-13 Sun 12:51

Announcements RSS